home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / bin / Xsession.z / Xsession
Encoding:
Korn shell script  |  2003-11-18  |  15.6 KB  |  667 lines

  1. #!/bin/ksh
  2.  
  3. # ###########################################################################
  4. #
  5. #   Xsession
  6. #
  7. #   TriTeal Enterprise Desktop (TED)
  8. #
  9. #   Configuration script for the Login Manager
  10. #
  11. #   (c) Copyright 1994  TriTeal Corporation 
  12. #   (c) Copyright 1993, 1994 Hewlett-Packard Company
  13. #   (c) Copyright 1993, 1994 International Business Machines Corp.
  14. #   (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  15. #   (c) Copyright 1993, 1994 Novell, Inc.
  16. #
  17. #       ************** DO NOT EDIT THIS FILE **************
  18. #
  19. #   /usr/dt/bin/Xsession is a factory-default file and will
  20. #   be unconditionally overwritten upon subsequent installation.
  21. #   Modification is discouraged.
  22. #
  23. #   $XConsortium: Xsession.src /main/cde1_maint/7 1995/11/17 14:43:10 gtsang $
  24. #
  25. #   @(#)TED Version: TED 5.3.3  06-5303-00
  26. #   @(#)TED FileVersion: Xsession: $Id: Xsession.src,v 1.1 2000/04/18 22:03:21 simon.longdrop.melbourne.1.com Exp $
  27. #
  28. # ###########################################################################
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. # ###########################################################################
  78. #   This script starts the user's session. It searches for one of three
  79. #   types of startup mechanisms, in the following order:
  80. #     DT     existence of CDE DT Session Manager on the system
  81. #     XDM    "$HOME/.xsession" (executable)
  82. #     xinit  "$HOME/.x11start"  (executable)
  83. #   If none of these startup mechanisms exist, a default window manager
  84. #   and terminal emulator client are started.
  85. # ##########################################################################
  86.  
  87. #
  88. # Variables must be explicitly exported
  89. set +a
  90.  
  91. # ###########################################################################
  92. #   Initialize session startup logging
  93. # ##########################################################################
  94.  
  95.  
  96. #
  97. # send startlog setup errors to a temporary log file so problems are easier
  98. # to debug.  the file is /var/dt/tmp/<username>_DISPLAY=<display>.
  99. # this works when there are only one or two users obtaining a session from a
  100. # host, but there is a potential to fill up /var (or even use all inodes) if
  101. # there are, say, two hundred users with X terminals trying to obtain
  102. # sessions.  so if the file doesn't contain anything, we will remove it below,
  103. # after the startlog has been setup.
  104. #
  105.   exec >/var/dt/tmp/${USER}_DISPLAY=${DISPLAY} 2>&1
  106.  
  107.  
  108.   LOGDIR=$HOME/.dt
  109.   LOGFILENAME=$LOGDIR/startlog
  110.   
  111.   if [ ! -d $LOGDIR ]; then
  112.     \mkdir $LOGDIR
  113.     if [ -d $LOGDIR ]; then
  114.       \chmod 755 $LOGDIR
  115.     fi
  116.   fi
  117.  
  118.   [ -f $LOGFILENAME.older ] && \rm -f $LOGFILENAME.older
  119.   [ -f $LOGFILENAME.old ] && \mv -f $LOGFILENAME.old $LOGFILENAME.older
  120.   [ -f $LOGFILENAME ] && \mv -f $LOGFILENAME $LOGFILENAME.old
  121.   \touch $LOGFILENAME
  122.  
  123.   if [ -w $LOGFILENAME ]; then
  124.     \exec >>$LOGFILENAME 2>&1
  125.   fi
  126.  
  127.  
  128. #
  129. # remove the temporary log file used to track startlog setup errors, if and
  130. # only if it is empty.
  131. #
  132. if [ ! -s /var/dt/tmp/${USER}_DISPLAY=${DISPLAY} ]
  133. then
  134.    \rm /var/dt/tmp/${USER}_DISPLAY=${DISPLAY}
  135. fi
  136.  
  137.  
  138.  
  139.   Log()
  140.   {
  141.     echo "--- $1" >>$LOGFILENAME 2>&1
  142.   }
  143.  
  144.   Log "$(date)"
  145.   Log "$0 starting..."
  146.  
  147.  
  148.  
  149. # ###########################################################################
  150. #   Global environment section
  151. #    DT pre-sets the following environment variables for each user.
  152. #    
  153. #     (internal)
  154. #     DISPLAY      set to the value of the first field in the Xservers file.
  155. #     HOME         set to the user's home directory (from /etc/passwd)
  156. #     LANG         set to the display's current NLS language (if any)
  157. #     LC_ALL       set to the value of $LANG
  158. #     LOGNAME      set to the user name
  159. #     PATH         set to the value of the Dtlogin "userPath" resource
  160. #     USER         set to the user name
  161. #     SHELL        set to the user's default shell (from /etc/passwd)
  162. #     TZ           set to the value of the Dtlogin "timeZone" resource
  163. #
  164. #     (Xsession)
  165. #     TERM         set to xterm
  166. #     EDITOR       set to the default editor
  167. #     KBD_LANG     set to the value of $LANG for certain languages
  168. #     MAIL         set to "/usr/mail/$USER"
  169. #    Three methods are available to modify or add to this list depending 
  170. #    on the desired scope of the resulting environment variable. 
  171. #    
  172. #     1. X server and/or all users on a display       (Xconfig file)
  173. #     2. all users on a display                       (Xsession file)
  174. #     3. individual users                             (.dtprofile file)
  175. #    See DT on-line help, the DT Users Guide, or the Dtlogin(1X) man
  176. #    page for details on setting environment variables.
  177. #     
  178. #     
  179. #      
  180. # ###########################################################################
  181.  
  182.   [ -z "$EDITOR" ] && EDITOR=/usr/dt/bin/dtpad
  183.   [ -z "$MAIL" ] && MAIL="/usr/mail/$USER"
  184.   [ -z "$LANG" ] && LANG="C"
  185.   TERM=dtterm
  186.  
  187.  
  188.   SESSION_SVR=`/usr/bsd/hostname`
  189.  
  190.   export PATH EDITOR MAIL TERM SESSION_SVR LANG
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.   #
  202.   # check if network is configured. If not, set environment variable
  203.   # so that tooltalk will use localhost/loopback rather than system
  204.   # name
  205.   status="1"
  206.  
  207.  
  208.  
  209.  
  210.  
  211.   if [ "$status" = "0" ]
  212.   then
  213.      export DTNONETWORK=true
  214.   fi
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.   #
  225.   # Locate configuration file directories
  226.   #
  227.   XDIR="/usr/bin/X11"
  228.   DT_BINPATH=/usr/dt/bin
  229.   DT_INSTALL_CONFIG=/usr/dt/config
  230.   DT_CONFIG=/etc/dt/config
  231.   DT_CONFIG_PATH="$DT_CONFIG $DT_INSTALL_CONFIG"
  232.  
  233. # ###########################################################################
  234. #
  235. #  Default desktop component configuration variable settings
  236. #
  237. #  This section sets the default value for variables controlling
  238. #  some desktop components.
  239. #
  240. # ###########################################################################
  241.  
  242.   # 
  243.   # Input method server startup
  244.   # 
  245.   if [ -z "$DTSTARTIMS" ]; then
  246.      DTSTARTIMS=True
  247.   fi
  248.  
  249.   if [ "$DTSTARTIMS" = "False" ]; then
  250.      unset DTSTARTIMS
  251.   fi
  252.  
  253.   # 
  254.   # Default desktop screen saver action list 
  255.   #  
  256.   export DTSCREENSAVERLIST="StartDtscreenSwarm StartDtscreenQix \
  257.     StartDtscreenFlame StartDtscreenHop StartDtscreenImage StartDtscreenLife \
  258.     StartDtscreenRotor StartDtscreenPyro StartDtscreenWorm StartDtscreenBlank"
  259.  
  260.   # 
  261.   # Session startup clients and args
  262.   # 
  263.   if [ "$SESSIONTYPE" = "altDt" ]; then
  264.       dtstart_session[0]="$SDT_ALT_SESSION"
  265.  
  266.       dtstart_hello[0]="$SDT_ALT_HELLO"
  267.  
  268.   else
  269.       dtstart_session[0]="$DT_BINPATH/dtsession"
  270.  
  271.       dtstart_hello[0]="$DT_BINPATH/dthello &"
  272.  
  273.   fi
  274.   dtstart_session[1]="$HOME/.xsession"
  275.   dtstart_session[2]="$HOME/.x11start"
  276.   dtstart_session[3]="$XBIN/xterm -geometry 80x24+10+10"
  277.  
  278.   dtstart_hello[1]="$XDIR/xsetroot -default &"
  279.  
  280.   dtstart_searchpath="$DT_BINPATH/dtsearchpath -ksh"
  281.   dtstart_ttsession="$DT_BINPATH/ttsession -s"
  282.   dtstart_dtdbcache="$DT_BINPATH/dtdbcache -init"
  283.   dtdbcacherm="rm -f /tmp/dtdbcache_$DISPLAY"
  284.   dtstart_appgather="$DT_BINPATH/dtappgather &"
  285.  
  286.  
  287.   xdmstart_session[0]="$HOME/.xsession"
  288.   xdmstart_session[1]="/usr/lib/X11/xdm/Xsession"
  289.   xdmstart_session[2]="xterm -geometry 80x24+10+10 -ls"
  290.  
  291.   xdmstart_hello="$XDIR/xsetroot -default &"
  292.  
  293.  
  294.   SESSIONLOGDIR=$LOGDIR/sessionlogs
  295.   SESSIONLOGFILENAME="$SESSIONLOGDIR/$SESSION_SVR"_DISPLAY=$DISPLAY
  296.  
  297.   if [ ! -d $SESSIONLOGDIR ]; then
  298.     \mkdir $SESSIONLOGDIR
  299.     if [ -d $SESSIONLOGDIR ]; then
  300.       \chmod 755 $SESSIONLOGDIR
  301.     fi
  302.   fi
  303.  
  304.   touch $SESSIONLOGFILENAME
  305.  
  306.   if [ -w $SESSIONLOGFILENAME ]; then
  307.       dtstart_sessionlogfile="$SESSIONLOGFILENAME"
  308.   else
  309.       dtstart_sessionlogfile="/dev/null"
  310.   fi
  311.  
  312.   rm -f $SESSIONLOGFILENAME
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.   #
  324.   # Determine Xsession parent
  325.   #
  326.  
  327.  
  328.  
  329.   pexec=$(LC_TIME=C ps -p $PPID | awk 'NR==2 {print $4}')
  330.  
  331.  
  332.  
  333.   Log "Xsession started by $pexec"
  334.  
  335.  
  336. # ###########################################################################
  337. #  
  338. # Append desktop font aliases to font path
  339. #
  340. # ###########################################################################
  341.  
  342.  
  343.  
  344.  
  345.   if [ "${pexec##*/}" != "dtlogin" ]; then
  346.     #
  347.     # If Xsession launched by dtlogin, it is assumed that the desktop
  348.     # font path has already been added by Xsetup, so no need to add it here.
  349.     # 
  350.  
  351.  
  352.     $XDIR/xset fp default
  353.  
  354.  
  355.     #
  356.     # Append desktop font paths. Note: these directories should be
  357.     # accessable by the X server. The file precedence is:
  358.     #
  359.     #   /etc/dt/config/xfonts/C
  360.     #   /usr/dt/config/xfonts/C
  361.     #   /etc/dt/config/xfonts/$LANG
  362.     #   /usr/dt/config/xfonts/$LANG
  363.     #
  364.  
  365.     Log "setting font path..."
  366.  
  367.  
  368.     if [ "$DTXSERVERLOCATION" != "remote" ]; then
  369.  
  370.       #
  371.       # Since X server is local, optimize by checking local desktop
  372.       # font directories and making one call to xset.
  373.       #
  374.  
  375.       if [ -f /etc/dt/config/xfonts/C/fonts.dir ]; then
  376.           fontpath=/etc/dt/config/xfonts/C
  377.       fi
  378.  
  379.       if [ -f /usr/dt/config/xfonts/C/fonts.dir ]; then
  380.         if [ -z "$fontpath" ]; then
  381.           fontpath=/usr/dt/config/xfonts/C
  382.         else
  383.           fontpath=$fontpath,/usr/dt/config/xfonts/C
  384.         fi
  385.       fi
  386.  
  387.       if [ "$LANG" != "C" ]; then
  388.         if [ -f /etc/dt/config/xfonts/$LANG/fonts.dir ]; then
  389.           if [ -z "$fontpath" ]; then
  390.             fontpath=/etc/dt/config/xfonts/$LANG
  391.           else
  392.             fontpath=$fontpath,/etc/dt/config/xfonts/$LANG
  393.           fi
  394.         fi
  395.       fi
  396.  
  397.       if [ "$LANG" != "C" ]; then
  398.         if [ -f /usr/dt/config/xfonts/$LANG/fonts.dir ]; then
  399.           if [ -z "$fontpath" ]; then
  400.             fontpath=/usr/dt/config/xfonts/$LANG
  401.           else
  402.             fontpath=$fontpath,/usr/dt/config/xfonts/$LANG
  403.           fi
  404.         fi
  405.       fi
  406.  
  407.  
  408.       if [ ! -z "$fontpath" ]; then
  409.         $XDIR/xset fp+ $fontpath
  410.       fi
  411.  
  412.  
  413.     else
  414.       #
  415.       # Since X server not local, we don't know if the desktop font
  416.       # directories exist on the X server machine, so we have to
  417.       # set them one at a time.
  418.       #
  419.  
  420.       $XDIR/xset fp+ /etc/dt/config/xfonts/C 1>/dev/null
  421.  
  422.       $XDIR/xset fp+ /usr/dt/config/xfonts/C 1>/dev/null
  423.  
  424.       if [ "$LANG" != "C" ]; then 
  425.         $XDIR/xset fp+ /etc/dt/config/xfonts/$LANG 1>/dev/null
  426.       fi
  427.  
  428.       if [ "$LANG" != "C" ]; then
  429.         $XDIR/xset fp+ /usr/dt/config/xfonts/$LANG 1>/dev/null
  430.       fi
  431.     fi
  432.  
  433.   fi 
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444. # ###########################################################################
  445. #   Source user's desktop profile
  446. #   This section determines if the user has a desktop profile in their
  447. #   home directory. If not, the desktop default profile is copied to
  448. #   the home directory. The desktop profile is then sourced. The purpose
  449. #   is to incorporate any per-user/per-session environment customizations
  450. #   and thereby propagate them to applications and desktop components.
  451. # ###########################################################################
  452.  
  453.  
  454.   DTSYSPROFILE=sys.dtprofile
  455.   DTPROFILE=.dtprofile
  456.  
  457.   if [ ! -f $HOME/$DTPROFILE ]; then
  458.     for i in $DT_CONFIG_PATH
  459.     do
  460.       if [ -f $i/$DTSYSPROFILE ]; then
  461.         /usr/bin/awk '
  462.           BEGIN {printit=1}
  463.           /SYSPROFILE COMMENT START/ {printit=0; next}
  464.           /SYSPROFILE COMMENT END/ {printit=1; next}
  465.           printit==1 {print}' <$i/$DTSYSPROFILE >$HOME/$DTPROFILE
  466.         /bin/chmod 755 $HOME/$DTPROFILE
  467.         break
  468.       fi
  469.     done
  470.   fi
  471.  
  472.   #
  473.   # source the .dtprofile.
  474.   #
  475.   if [ -f $HOME/$DTPROFILE ]; then
  476.     Log "sourcing $HOME/$DTPROFILE..."
  477.     . $HOME/$DTPROFILE
  478.   fi
  479.  
  480.  
  481. # ###########################################################################
  482. #  External Xsession processing section
  483. #  This section searches the Xsession.d subdirectory and sources
  484. #  the files contained therein.  The purpose is to set up any
  485. #  per-user/per-session environment customizations and thereby propagate
  486. #  them to applications and desktop components.
  487. # ##########################################################################
  488.  
  489.   DT_XSESSION_DIR=Xsession.d
  490.  
  491.   for i in $DT_CONFIG_PATH
  492.   do
  493.     if [[ -d $i/$DT_XSESSION_DIR ]]; then
  494.       # 
  495.       # Run custom Xsession scripts for this session.
  496.       # 
  497.       for SCRIPT in $(ls $i/$DT_XSESSION_DIR); do
  498.           if [ -x $i/$DT_XSESSION_DIR/$SCRIPT -a \
  499.         \( ! -d $i/$DT_XSESSION_DIR/$SCRIPT \) ]; then
  500.                Log "sourcing $i/$DT_XSESSION_DIR/$SCRIPT..."
  501.                . $i/$DT_XSESSION_DIR/$SCRIPT
  502.           fi
  503.       done
  504.     fi
  505.   done
  506.  
  507.  
  508.  
  509. # Add optional dtstart_session arguments
  510.   dtstart_session[0]="${dtstart_session[0]} ${TT_DTSESSION_OPT_ARGS}"
  511.  
  512.  
  513. # ###########################################################################
  514. #   Startup section.
  515. #      
  516. #   Note: The ksh syntax ${parameter%% *} is used when appropriate to
  517. #         remove any command line options that may have been included
  518. #         in the definition of a DT executable below.
  519. #      
  520. # ###########################################################################
  521.  
  522. # Return first command in array named by $1 that is executable
  523. GetFirst()
  524. {
  525.   let i=0
  526.   while true; do
  527.     eval "cmd=\${$1[$i]}"
  528.     [ -z "$cmd" ] && break
  529.     [ -x "${cmd%% *}" ] && echo "$cmd" && break
  530.     Log "could not start $cmd"
  531.     let i=$i+1
  532.   done
  533. }
  534.  
  535. # Start first command in array named by $1 that is executable. If
  536. # $2 is 'eval', command result will be 'eval'ed. 
  537. StartFirst()
  538. {
  539.   first=$(GetFirst $1)
  540.   if [ ! -z "$first" ]; then
  541.     Log "starting $first"
  542.     if [ "$2" = "eval" ]; then
  543.       eval `eval "PATH=$DT_BINPATH:$PATH $first"`
  544.     else
  545.       eval "PATH=$DT_BINPATH:$PATH $first"
  546.     fi
  547.   fi
  548. }
  549.  
  550.   # 
  551.   # Prepare for session startup
  552.   # 
  553.  
  554.   if [ "$DTSOURCEPROFILE" = "true" ]
  555.   then
  556.     case ${SHELL##*/} in
  557.        sh | ksh | dtksh) shellprofile="$HOME/.profile";;
  558.        bash) shellprofile="$HOME/.bash_profile";;
  559.        csh | tcsh) shellprofile="$HOME/.login";;
  560.        *) Log "non-standard shell $SHELL"
  561.     esac
  562.   fi
  563.  
  564.   if [ "$shellprofile" -a ! -f "$shellprofile" ]
  565.   then
  566.     Log "could not read $shellprofile"
  567.     unset shellprofile
  568.   fi
  569.  
  570.   if [ "$SESSIONTYPE" = "xdm" ]; then
  571.     startup=$(GetFirst xdmstart_session)    # get xdm session client
  572.  
  573.     StartFirst xdmstart_hello               # start xdm hello client
  574.  
  575.   else
  576.     startup=$(GetFirst dtstart_session)     # get desktop session client
  577.  
  578.     StartFirst dtstart_hello                # start desktop hello client
  579.  
  580.     StartFirst dtstart_searchpath eval      # setup desktop search paths
  581.  
  582.  
  583.     tooltalk=$(GetFirst dtstart_ttsession)  # get tooltalk client
  584.     dtdbcache=$(GetFirst dtstart_dtdbcache) # get dtdbcache client
  585.  
  586.  
  587.     StartFirst dtstart_appgather            # setup session applications
  588.   fi
  589.  
  590.   # 
  591.   # Start the session.
  592.   # 
  593.  
  594.   if [ $shellprofile ]; then
  595.     Log "execing $startup using $shellprofile..."
  596.  
  597.     source_profile=". $shellprofile"
  598.     source_login="source $shellprofile"
  599.   else
  600.     Log "execing $startup..."
  601.  
  602.     source_profile="echo 'not sourcing $HOME/.profile (see $HOME/.dtprofile)'"
  603.     source_login="echo 'not sourcing $HOME/.login (see $HOME/.dtprofile)'"
  604.   fi
  605.  
  606.   if [ -z "$dtdbcache" ]; then
  607.     dtdbcache="echo could not start $dtstart_dtdbcache"
  608.   fi
  609.  
  610.   export DT=true;
  611.   case ${SHELL##*/} in
  612.       sh | bash) $SHELL -c "$source_profile; \
  613.                unset DT; \
  614.                $dtdbcache; \
  615.                            PATH=/usr/dt/bin:\$PATH $tooltalk;   \
  616.                            $startup > $dtstart_sessionlogfile 2>&1" ;;
  617.  
  618.       ksh | dtksh) $SHELL -c "$source_profile; \
  619.                unset DT; \
  620.                $dtdbcache; \
  621.                            PATH=/usr/dt/bin:\$PATH $tooltalk;\
  622.                            $startup >| $dtstart_sessionlogfile 2>&1" ;;
  623.  
  624.       csh | tcsh) $SHELL -c "unsetenv _ PWD;       \
  625.                            $source_login; \
  626.                            unsetenv DT;          \
  627.                $dtdbcache; \
  628.                            (set path = ( $DT_BINPATH \$path ); $tooltalk ); \
  629.                            $startup  >&! $dtstart_sessionlogfile" ;;
  630.  
  631.       *) unset DT
  632.      $dtdbcache
  633.          StartFirst dtstart_ttsession
  634.          $startup >| $dtstart_sessionlogfile 2>&1 ;;
  635.   esac
  636.  
  637. $dtdbcacherm        # remove the actions/datatypes cachefile
  638.  
  639. # ####################         eof      #################################
  640.